/*
 * Copyright (C) 2011 Mette Bank, Rikke Jensen, Kenneth Brodersen, Thomas Pedersen
 * 
 * This file is part of digiPECS.
 * 
 * digiPECS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * digiPECS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with digiPECS.  If not, see <http://www.gnu.org/licenses/>.
 */

package sw6.digipecs;

import sw6.digipecs.digicustom.AdminMenu;
import sw6.digipecs.digicustom.Keypad;
import sw6.digipecs.user.MainActivity;
import android.content.Intent;
import android.view.KeyEvent;

public class DigiPecsNoKeysActivity extends DigiPecsActivity {

	// Deactivating all keys:
	boolean mSearchDown = false;
	boolean mBackDown = false;

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
			mBackDown = true;
			break;
		case KeyEvent.KEYCODE_SEARCH:
			mSearchDown = true;
			break;
		case KeyEvent.KEYCODE_MENU:
			return false;
		}
		
		if (mBackDown && mSearchDown) {
			mBackDown = false;
			mSearchDown = false;
			Intent intent = new Intent(); 
			intent.setClass(this, Keypad.class);
			intent.putExtra(Keypad.hidden_field, true);
			startActivityForResult(intent, 1);
		}
		
		return true;
	}
	
	

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == 1) {
			if (resultCode == 1337) {
				MainActivity.setRunning(false);
				
				Intent intent = new Intent(this, AdminMenu.class);
				startActivity(intent);
			}
		}
	}

	@Override
	public boolean onKeyLongPress(int keyCode, KeyEvent event) {
		return true;
	}

	@Override
	public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
		return true;
	}

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
			mBackDown = false;
			break;
		case KeyEvent.KEYCODE_SEARCH:
			mSearchDown = false;
			break;
		case KeyEvent.KEYCODE_MENU:
			return false;
		}
		return true;
	}
}
